<!DOCTYPE HTML>
<html>
<head>
  <title>Error</title>
  <meta name="viewport"
        content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no"/>
  <script src="/scripts/jquery.min.js"></script>
  <link rel="stylesheet" href="/stylesheets/formdata.css">
  <link rel="stylesheet" href="/scripts/miniui/themes/default/miniui.css">
  <link rel="stylesheet" href="/scripts/miniui/themes/icons.css">
  <link rel="stylesheet" href="/scripts/miniui/themes/bootstrap/skin.css">

  <script src="/scripts/miniui/miniui.js"></script>
  <script src="/qiniuJs/liveFormdata.js"></script>
  <script src="/qiniuJs/livePicFormdata.js"></script>

</head>
<body>

<div id="form1" style="padding-left: 30px;margin-top: 30px">
  <div class="input_div" style="text-align: center;width: 100%">
    <div style="margin-bottom: 10px;">
      <span>商品名称：</span>
      <input id="shopGoodsOId" class="mini-buttonedit" onbuttonclick="onButtonShopGoods" name="a" textName="b"/>
    </div>
    <div style="margin-bottom: 20px;">
      <span>部落名称：</span>
      <input id="tribeOId" class="mini-buttonedit" onbuttonclick="onButtonTribe" name="a" textName="b"/>
    </div>
  </div>
  <div style="margin: 0 auto;text-align: center">
    <a class="mini-button " iconCls="icon-ok" onclick="addClick()">确定</a>
    <a class="mini-button" iconCls="icon-cancel" onclick="onCancel">取消</a>
  </div>
</div>
</body>
<script>
  function addClick() {
    var form = new mini.Form("#form1");
    form.validate();
    if (form.isValid() == false) {
      alert("请正确填写数据")
      return
    }
    ;
    var shopGoodsOId = mini.get("shopGoodsOId").getValue();
    var tribeOId = mini.get("tribeOId").getValue();
    if (shopGoodsOId == '' ){
      alert('请选择商品！')
      return
    } else if (tribeOId == '' ){
      alert('请选择部落！')
      return
    }
    $.ajax({
      type: "POST",
      url: "/getdata/goodsTribeCorrelationAdd",
      data: {
        shopGoodsOId: shopGoodsOId,
        tribeOId: tribeOId,
      },

      success: function (result) {
//        console.log(result)
        if (result != false){
          CloseWindow("save");
        }
      },
      fail: function (error) {
        console.log(error)
        CloseWindow("close");
      }
    })
  }

  //    关闭窗口
  function CloseWindow(action) {
    if (action == "close" && form.isChanged()) {
      if (confirm("数据被修改了，是否先保存？")) {
        return false;
      }
    }
    if (window.CloseOwnerWindow) return window.CloseOwnerWindow(action);
    else window.close();
  }

  function onOk(e) {
    SaveData();
  }

  function onCancel(e) {
    CloseWindow("cancel");
  }

  function onButtonTribe(e) {
    var btnEdit = this;
    mini.open({
      url: "/editor/tribeChoice",
      title: "选择列表",
      width: 700,
      height: 450,
      ondestroy: function (action) {
        if (action == "ok") {
          var iframe = this.getIFrameEl();
          var data = iframe.contentWindow.GetData();
          data = mini.clone(data);    //必须
          if (data) {
            btnEdit.setValue(data.id);
            btnEdit.setText(data.text);
          }
        } else {
          btnEdit.setText("");
          btnEdit.setValue("");
        }

      }
    });

  }

  function onButtonShopGoods(e) {
    var btnEdit = this;
    mini.open({
      url: "/editor/shopGoodsChoice",
      title: "商品列表",
      width: 1100,
      height: 450,
      ondestroy: function (action) {
        if (action == "ok") {
          var iframe = this.getIFrameEl();
          var data = iframe.contentWindow.GetData();
          data = mini.clone(data);    //必须
          if (data) {
            btnEdit.setText(data.text);
            btnEdit.setValue(data.id);
          }
        }else {
          btnEdit.setText("");
        }

      }
    });

  }
</script>
</html>